<?php
/**
 * 商品分类功能测试
 */

// 模拟请求数据
$testData = [
    'name' => '测试分类',
    'parent_id' => 0,
    'sort' => 1
];

echo "=== 商品分类功能测试 ===\n";
echo "测试数据: " . json_encode($testData, JSON_UNESCAPED_UNICODE) . "\n\n";

// 模拟API响应
$responses = [
    'list' => [
        'code' => 20000,
        'msg' => '获取成功',
        'data' => [
            'list' => [
                [
                    'id' => 1,
                    'name' => '电子产品',
                    'fid' => 0,
                    'sort' => 1,
                    'status' => 1,
                    'created_at' => time(),
                    'updated_at' => time(),
                    'children' => [
                        [
                            'id' => 2,
                            'name' => '手机',
                            'fid' => 1,
                            'sort' => 1,
                            'status' => 1,
                            'created_at' => time(),
                            'updated_at' => time()
                        ]
                    ]
                ]
            ],
            'total' => 1
        ]
    ],
    'add' => [
        'code' => 20000,
        'msg' => '添加成功',
        'data' => [
            'id' => 3,
            'name' => '测试分类',
            'fid' => 0,
            'sort' => 1,
            'status' => 1,
            'created_at' => time(),
            'updated_at' => time()
        ]
    ],
    'delete' => [
        'code' => 20000,
        'msg' => '删除成功',
        'data' => null
    ]
];

echo "1. 获取分类列表响应:\n";
echo json_encode($responses['list'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";

echo "2. 添加分类响应:\n";
echo json_encode($responses['add'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";

echo "3. 删除分类响应:\n";
echo json_encode($responses['delete'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";

echo "=== 功能说明 ===\n";
echo "- 支持二级分类管理\n";
echo "- 分类列表以树形结构显示\n";
echo "- 支持添加顶级分类和子分类\n";
echo "- 删除分类时会检查是否有子分类\n";
echo "- 分类按排序字段排序\n";
echo "- 遵循编码规范，使用统一的错误处理\n"; 